####### Step [Start] #######
# Output selection code : Main_output_selection.py
This python code demonstrates how to find the outputs for the LSTM model.
# Input selection code : Main_input_selection.py
This python code demonstrates how to find the inputs for the LSTM model.
# Long short term memory (LSTM) model of reduced-order system : Main_LSTM_target_reduced_model.py, Saved Models3 folder, LSTM_model.py, Final_data_set.csv
## Introduction
This python code demonstrates how to identify an LSTM model that models the selected outputs using simulation data from the first principle model. 
The main code can be found in the **Main_LSTM_target_reduced_model.py** file. 
There exists other file **LSTM_model.py** which contain functions that are employed by the main code. Appropriate descriptions and comments have been provided in each file. 
The code provides training data obtained by simulating the first principle model for a reactor-separator system. The entire data can be found in the **Final_data_set.csv*** file.
After executing the main code, the results that illustrate the performance of identified LSTM model can be found.
The weights and biases of the trained LSTM model can be found in the **Saved Models3** folder.

## Requirements
This code requires **Python 3** as well as some other relevant packages  such as **numpy, tensorflow, pandas**, etc. 
The configuration file, **env_ioEKF.yml**, of a conda environment which contains the required packages has been provided. 
This environment can be created by executing the following line in the Anaconda command prompt or any suitable shell

``` 
conda env create -f env_ioEKF.yml
```
Running the above command will create a conda environment named **ioEKF**.

To create MPC environment use the link and follow instructions:
[Link text Here](https://sites.engineering.ucsb.edu/~jbraw/software/mpctools/download/index.html)

## Usage 
Firstly, one will have to activate a python environment that contains the required packages. For example, the **ioEKF** environment can be activated as follows

```
conda activate ioEKF
```

Next, to train the LSTM model, the **Main_LSTM_target_reduced_model.py** can be executed in any python IDE. Alternatively, command line enthusiast may execute the following line

```
python Main_LSTM_target_reduced_model.py
```

# Reduced-order estimator : Main_reduced_estimator.py, Saved Models3 folder, LSTM_model.py

This python code demonstrates how to estimate states using an LSTM model that models the selected outputs and selected inputs.
The main code can be found in the **Main_reduced_estimator.py** file. The weights and biases of the trained LSTM model can be loaded from the **Saved Models3** folder. 
There exists other file **LSTM_model.py** which contain functions that are employed by the main code. 
After executing the main code, the results that illustrate the performance of reduced-order estimation can be found.

# Scheme 2 Soft sensor design : Main_NN_softsensor.py, Final_data_set.csv
This python code demonstrates how to identify an MLP (Multi-layer Perceptron) NN (Neural network) model that models the measured variables with target variable using simulation data from the first principle model. 
The main code can be found in the **Main_NN_softsensor.py** file. 
The entire data can be found in the **Final_data_set.csv*** file.
After executing the code, the results that illustrate the performance of reduced-order estimation can be found.

# Scheme 3 Full state estimation : Full_state_estimator folder
This python code demonstrates how to estimate all the states from the first principle model.
The main estimation code can be found in the **Main_Full_state_estimator.py** file. The first principle model code can be found in the **fullsystem_9states_EKF.py** file.
The test input data can be found in the **x_test_unscaled.txt*** file.
After executing the code, the results that illustrate the performance of full state estimation can be found.

# Scheme 4 Soft sensor design : Saved Models ss folder, Main_softsensor_LSTM.py
This python code demonstrates how to identify an LSTM model that models the all measured variables and past target variables with target variable using simulation data from the first principle model. 
The main code can be found in the **Main_softsensor_LSTM.py** file. 
The entire data can be found in the **Final_data_set.csv*** file.
After executing the code, the results that illustrate the performance of reduced-order estimation can be found.

## Feedback
Please get in touch via [mail](mailto:jinfeng@ualberta.ca) if you have questions.

####### Step [End] #######